<?php
/**
 * @author bbernath
 *         Date: 16.11.13
 *         Time: 13:49
 * @version 1.0.1
 */

echo "<h3>&raquo; Kommentare verwalten</h3>";
echo "&laquo; <a href=index.php?action=administration&site=news&userid=" . $_GET['userid'] . ">News verwalten</a><br><br>";
?>
<table border="1" id="news">
    <tr>
        <td><b>ID:</b></td>
        <td><b>Kommentar zu folgenden News:</b></td>
        <td><b>Geschrieben von:</b></td>
        <td colspan="2"><b>M&ouml;glichkeiten:</b></td>
    </tr>

    <?php
    $sql = "select nc.id, n.topic, nc.name from news_comments nc, news n where nc.news = n.id";
    $stmt = $db->prepare($sql);
    $stmt->execute();
    $stmt->bind_result($id, $topic, $name);
    $comments = array();
    while ($stmt->fetch()) {
        $comments[] = array(
            'id' => $id,
            'topic' => $topic,
            'name' => $name
        );
    }
    $stmt->close();

    if (count($comments)) {
        foreach ($comments as $comments_entry) {
            echo "<tr>";
            echo "<td>#" . $comments_entry['id'] . "</td>";
            echo "<td>" . $comments_entry['topic'] . "</td>";
            echo "<td>" . $comments_entry['name'] . "</td>";
            echo "<td><a href=index.php?action=administration&site=edit_comment&id=" . $comments_entry['id'] . "&userid=" . $_GET['userid'] . ">bearbeiten</a></td>";
            echo "<td><a href=index.php?action=administration&site=delete_comment&id=" . $comments_entry['id'] . "&userid=" . $_GET['userid'] . ">l&ouml;schen</a></td>";
            echo "</tr>";
        }
    } else {
        echo "<tr><td colspan='5'>Keine Kommentare vorhanden.</td></tr>";
    }
    ?>
</table>
<br><br>&raquo; <a href='index.php?action=administration'>Administration beenden</a>